<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\tool\Result;
use think\facade\View;
use think\Response;
use app\common\model\News as NewsModel;

class News extends Base
{
    public function index(): string
    {
        return View::fetch();
    }

    public function getList(): Response
    {
        $sort = [['key' => 'sort', 'value' => 'desc'], ['key' => 'id', 'value' => 'asc']];

        return Result::fastReturn(NewsModel::getPageList([], 'id,title,describe,images,create_time',
            $this->getPage(), $this->getLimit(), true, [], [], $sort));
    }

    public function details($id): string|Response
    {
        $info = NewsModel::where(['id' => $id, 'status' => 1])->find();
        if (!$info) {
            return redirect('/');
        }
        View::assign('info', $info);

        return View::fetch();
    }
}